package com.yuwei.home.parking_space_management

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter
import com.yuwei.common.entity.BannerEntity


/**
 * 首页的banner适配器
 */
class HomeBannerAdapter(data:List<BannerEntity>):BannerAdapter<BannerEntity,HomeBannerAdapter.BannerViewHolder>(data) {
    inner class BannerViewHolder(val imageView: ImageView):RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder,
        data: BannerEntity,
        position: Int,
        size: Int
    ) {
        Glide.with(holder.itemView).load(data.image).into(holder.imageView)
    }
}